
<?php
//kurs/wp-content/plugins/courses/coursesuser.php
function get_lesson(){
global $current_user,$wpdb;

$cur = $_REQUEST['cur'];
$les = $_REQUEST['les'];



            $arr=array(); $row=array();$adr=array();

     $sql = "SELECT obadr,obklu,obzna FROM 1webuniver_zw_".$cur."_lessons_data WHERE  templid='$les' ORDER BY obadr" ;

      $lessons = $wpdb->get_results($sql, ARRAY_A);

                            
                        foreach ($lessons as $lesson) {
                                $exid = $lesson['obadr'];
                                $exklu = $lesson['obklu'];
                                $exdat = $lesson['obzna'];


                                 for ($i=0;$i < strlen($exid);$i++) {
                                     $adr[$i] = substr($exid,$i,1);
                                     if($adr[$i]=='c')$adr[$i]='children';
                                 }

 $lev = count($adr);
 $key = $exklu;
 if($exklu=='c')$key='children';if($exklu=='z')$key='children';if($exklu=='t')$key='text';if($exklu=='r')$key='ref';
 if($exklu=='h')$key='html';if($exklu=='s')$key='scr';if($exklu=='a')$key='i';if($exklu=='p')$key='place';
 if($exklu=='d')$key='dat';

 $val = stripslashes($exdat);
 if($val=='t')$val='true';if($val=='f')$val='false';if($val=='s')$val='scr';if($val=='h')$val='html';

     //   if($key = 'mat'){
        if(substr($val,0,2)=='(q'){ //указатель на то является ли значение "mat" строкой с данными или только ссылкой на запрос к базе
     //    $matar = explode('oo',$val);
     //    $tabl = $matar[0];
     //    $quer = $matar[1];
      //                                  $current_user
         //   $send = "SELECT * FROM ".$prefix."_".$tabl." WHERE

        }else{


       }


 $lev = count($adr);

 if ( $lev==1 )  $arr[ $adr[0] ][ $key ]=$val;
 if ( $lev==3 )  $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$key]=$val;
 if ( $lev==5 )  $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$key]= $val;
 if ( $lev==7 )  $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$key]= $val;
 if ( $lev==9 )  $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$adr[7]][$adr[8]][$key]= $val;
 if ( $lev==11 ) $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$adr[7]][$adr[8]][$adr[9]][$adr[10]][$key]= $val;
 if ( $lev==13 ) $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$adr[7]][$adr[8]][$adr[9]][$adr[10]][$adr[11]][$adr[12]][$key]= $val;
 if ( $lev==15 ) $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$adr[7]][$adr[8]][$adr[9]][$adr[10]][$adr[11]][$adr[12]][$adr[13]][$adr[14]][$key]= $val;
 if ( $lev==17 ) $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$adr[7]][$adr[8]][$adr[9]][$adr[10]][$adr[11]][$adr[12]][$adr[13]][$adr[14]][$adr[15]][$adr[16]][$key]= $val;
 if ( $lev==19 ) $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$adr[7]][$adr[8]][$adr[9]][$adr[10]][$adr[11]][$adr[12]][$adr[13]][$adr[14]][$adr[15]][$adr[16]][$adr[17]][$adr[18]][$key]= $val;
 if ( $lev==21 ) $arr[ $adr[0] ][ $adr[1] ][$adr[2]][$adr[3]][$adr[4]][$adr[5]][$adr[6]][$adr[7]][$adr[8]][$adr[9]][$adr[10]][$adr[11]][$adr[12]][$adr[13]][$adr[14]][$adr[15]][$adr[16]][$adr[17]][$adr[18]][$adr[19]][$adr[20]][$key]= $val;

 unset($adr);
      }

$output = json_encode($arr);

echo $output;


}
